package mc.support.taobao.api;

import mc.support.taobao.api.fields.GetItemCatsFields;
import com.taobao.api.TaobaoRequest;
import com.taobao.api.request.ItemcatsGetRequest;
import com.taobao.api.response.ItemcatsGetResponse;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA. <br/>
 * Author: francis Yun    <br/>
 * Date: 2013-12-09  <br/>
 */
public class GetItemCatsReq extends AbstractReq<GetItemCatsReq, ItemcatsGetResponse> {

    private Long parentCid;

    private Set<String> cids;

    private GetItemCatsFields fields;

    public GetItemCatsReq parentCid(Long parentCid) {
        this.parentCid = parentCid;
        return this;
    }

    public GetItemCatsReq cids(Set<String> cids) {
        this.cids = cids;
        return this;
    }

    public GetItemCatsReq fields(GetItemCatsFields fields) {
        this.fields = fields;
        return this;
    }

    public GetItemCatsReq addCid(String cid) {
        if ( null == cids ) {
            cids = new HashSet<String>();
        }
        cids.add( cid );
        return this;
    }

    @Override
    protected TaobaoRequest toRequest() {
        ItemcatsGetRequest req = new ItemcatsGetRequest();

        if ( null != fields ) {
            req.setFields( fields.toString() );
        }

        if ( null != parentCid ) {
            req.setParentCid( parentCid );
        }

        if ( null != cids && !cids.isEmpty() ) {
            req.setCids( setToString( cids ) );
        }

        return req;
    }

}
